<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.yaodian100.core.common.utils.ServerValue"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ include file="/taglibs.jsp"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> 	
<!-- 数字验证 -->
<script type="text/javascript" charset="UTF-8" src="<%=ServerValue.getMidContextPath()%>/js/jquery.alphanumeric.js"></script>
<link rel="stylesheet" type="text/css" media="screen" href="/css/ui.jqgrid.css" />
<script src="/js/grid.locale-en.js" type="text/javascript"></script>
<script src="/js/jquery.jqGrid.min.js" type="text/javascript" charset="UTF-8"></script>
<s:url var="supplierPops" value="/json/supplierPops.do"/>
<script language="javascript">
<!--
var content;
$().ready( function() {
	
	<c-rt:if test="${productSupplierApprove.newSupplierId eq '010000' or productSupplierApprove.newSupplierId eq '010001'}">
		$("#twSupplier").show();
	</c-rt:if>
	$("#newCost").numeric({allow:"."});
	$("#supplierParam").numeric();
	$("#getSupplier").click(function() {
		$("#spId").val("");
		$("#spName").val("");
		doAR('${supplierPops}', 'dialog'); 
		openDialog('供应商搜寻',content, 550, 440);
	});	 
	$("#getTwSupplier").click(function() {
		$("#spId").val("twSupplierIdParam");
		$("#spName").val("twSupplierCompanyName");
		doAR('${supplierPops}', 'dialog'); 
		openDialog('供应商搜寻',content, 550, 440);
	});	 
	
	$("#submitBtn").click(function(){
		if ( validateData() && chkSupplier()){
			$("#approveStatus").val("10");
			$("#supplierApproveForm").submit();
		}
	});

	$("#cancelBtn").click(function(){
		if ( validateData() && chkSupplier()){
			$("#approveStatus").val("20");
			$("#supplierApproveForm").submit();
		}
	});

	$("#approveCancelBtn").click(function(){
		if ( "" == $("#approveFailReason").val() ){
			alert("请输入审核失败原因");
			return false;
		}
		$("#supplierApproveForm").attr("action","saveApprove.do");
		$("#approveStatus").val("40");
		$("#supplierApproveForm").submit();
	});

	
	$("#approveOKBtn").click(function(){
		if ( chkSupplier() ){
			$("#approveStatus").val("30");
			$("#supplierApproveForm").attr("action","saveApprove.do");
			$("#supplierApproveForm").submit();
		}
	});		
	$("#notSaveBtn").click(function(){
		location.href="<%=ServerValue.getMidContextPath()%>/productSupplierApprove/search.do";
	});
});
function validateData(){
	if ( "" == $("#supplierIdParam").val() ){
		alert("请选择供应商");
		return false;
	}
	if ( "" == $("#newCost").val() || parseFloat($("#newCost").val()) == 0 ){
		alert("请输入新成本");
		return false;
	}
	if ( $("#supplierIdParam").val() == "010000" || $("#supplierIdParam").val() == "010001"){
		if ($("#twSupplierIdParam").val() == "" ){
			alert("请选择台湾馆供应商");
			return false;
		}
		if ( "${product.supplierId}" == $("#supplierIdParam").val() && "${product.twSupplierId}" == $("#twSupplierIdParam").val()){
			alert("请选择不同供应商");
			return false;
		}
	}else{
		if ( "${product.supplierId}" == $("#supplierIdParam").val()){
			alert("请选择不同供应商");
			return false;
		}
	}
	if ( parseFloat($("#newCost").val()) > parseFloat("${shelf.shelfPrice}") ){
		alert("成本不可高于现行售价");
		return false;
	}
	return true;
}
function chkSupplier(){
	if ( "${product.productType}" == 6 ){
		alert("N选M商品不可异动供应商");
		return false;
	}
	if ( "${product.isScm}" == "Y" ){
		alert("SCM转单商品不可异动供应商");
		return false;
	}
	if ( "${not empty addonsMain}" == "true" ){
		alert("搭售主商品不可异动供应商");
		return false;
	}			
	if ( "${not empty addons}" == "true" ){
		alert("该商品有设成搭售，请先移除搭售设定");
		return false;
	}
	if ( "${not empty nms}" == "true" ){
		alert("该商品有设成n选m，请先移除搭售设定");
		return false;
	}
	if ( "${chkHasInventory}" == "true"){
		alert("该商品尚有库存不可异动供应商");
		return false;
	}
	return true;
}
-->
</script>	
<style type="text/css">
.msg{float:left; line-height:1em; margin:0; display:block;border:1px solid #f66;padding:2px 5px;*padding:2px 5px 1px;}
.msg.rn{background-color:#fff2f2;border-color:#f66;}
</style>
<s:if test="hasActionErrors()">
	<s:actionerror cssClass="msg rn"/>
</s:if>
<s:if test="hasActionMessages()">
	<s:actionmessage cssClass="msg rn"/>
</s:if>
<p></p>		
<h1>商品供应商修改审核 - 维护<br/>
	<div class="f-link">
		<a href="<%=ServerValue.getMidContextPath()%>/product/list.do">回商品列表页</a>
		<a href="<%=ServerValue.getMidContextPath()%>/productSupplierApprove/search.do">回商品供应商修改审核列表页</a>
	</div>
</h1>
<br/>
<s:form action="save.do" method="post" id="supplierApproveForm">
	<table class="tb-data" width="100%">
		<tr>
			<th>商品名称(商品编号）</th>
			<td>${product.productName}(${product.productId})</td>
		</tr>			                    
	  <tr>
	  	<th>原供应商(供应商编号)
	  	<c-rt:if test="${not empty productSupplierApprove.newTwSupplierId or not empty oldTwSupplierId}">
	  	/原台湾馆供应商(台湾馆供应商编号）
	  	</c-rt:if>
	  	</th>
	  	<td>${oldSupplierCompanyName}(${oldSupplierId})
	  	<c-rt:if test="${not empty productSupplierApprove.newTwSupplierId or not empty oldTwSupplierId}">
	  	/${oldTwSupplierCompanyName}(${oldTwSupplierId})
	  	</c-rt:if>
	  	</td>
	  </tr>
	  <tr>
	  	<th>原成本</th>
	  	<td><fmt-rt:formatNumber value="${oldCost}" pattern="#######.0#"/></td>
	  </tr>
	  <c-rt:choose>
	  	<c-rt:when test="${approve eq 'Y'}">
			  <tr>
			  	<th>新供应商</th>
			  	<td>${supplierCompanyName}(${productSupplierApprove.newSupplierId})</td>
			  </tr>
			  <tr>
			  	<th>新成本</th>
			  	<td><fmt-rt:formatNumber value="${productSupplierApprove.newCost}" pattern="#######.0#"/>
			  	<span class="txt-rd">【※商品成本小数点2位数后无条件舍去】</span>
			  	</td>
			  </tr>
			  <c-rt:if test="${not empty productSupplierApprove.newTwSupplierId}">
			  <tr>
			  	<th>台湾馆供应商</th>
			  	<td colspan="3">${twSupplierCompanyName}(${productSupplierApprove.newTwSupplierId})</td>
			  </tr>
			  </c-rt:if>
			</c-rt:when>
			<c-rt:otherwise>
			  <tr>
			  	<th>新供应商</th>
			  	<td>
			  		<s:textfield name="newSupplierId" id="supplierIdParam" maxlength="6" readonly="readonly" value="%{productSupplierApprove.newSupplierId}"/>
						<img class="ui-icon ui-icon-search" src="/images/none.gif" style="height:16px; width:16px; position:relative; display:inline;" id="getSupplier"/>		
						<input type="text" id="supplierCompanyName" value="${supplierCompanyName}" readonly="readonly" size="60" style="border: 0px;"/>
			  	</td>
			  </tr>
			  <tr>
			  	<th>新成本</th>
			  	<td><input type="text" id="newCost" name="newCost" value="${productSupplierApprove.newCost}"/>
			  	<span class="txt-rd">【※商品成本小数点2位数后无条件舍去】</span>
			  	</td>
			  </tr>	
			  <tr id="twSupplier" style="display:none">
			  	<th>台湾馆供应商</th>
			  	<td colspan="3">
			  		<s:textfield name="newTwSupplierId" id="twSupplierIdParam"  maxlength="6" readonly="readonly" value="%{productSupplierApprove.newTwSupplierId}"/>
						<img class="ui-icon ui-icon-search" src="/images/none.gif" style="height:16px; width:16px; position:relative; display:inline;" 
								id="getTwSupplier"/>
						<input type="text" id="twSupplierCompanyName" value="${twSupplierCompanyName}" readonly="readonly" size="60" style="border: 0px;"/>
			  	</td>
			  </tr>		
			</c-rt:otherwise>
		</c-rt:choose>	
	  <c-rt:if test="${not empty productSupplierApprove.id}">
	  <tr>
	  	<th>状态</th>
	  	<td>${supplierApproveMenu.options[productSupplierApprove.approveStatus].name}</td>
	  </tr>	  
	  <tr>
	  	<th>申请人</th>
	  	<td>${productSupplierApprove.applyUser}</td>
	  </tr>
	  <tr>
	  	<th>申请时间</th>
	  	<td><fmt-rt:formatDate value="${productSupplierApprove.applyDate}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
	  </tr>	  
	  </c-rt:if>
	  <c-rt:if test="${approve eq 'Y'}">
		  <tr>
		  	<th>审核人员</th>
		  	<td>${loginUser}</td>
		  </tr>
		  <tr>
		  	<th>不同意原因</th>
		  	<td><input type="text" name="approveFailReason" id="approveFailReason" maxlength="255" size="100" value="${productSupplierApprove.approveFailReason}"/></td>
		  </tr>	
		   <tr>
		  	<th>建立者</th>
		  	<td>${productSupplierApprove.createUser}</td>
		  </tr>	
		  <tr>
		  	<th>建立日期</th>
		  	<td><fmt:formatDate value="${productSupplierApprove.createDate}" pattern="yyyy-MM-dd HH:mm:ss" /></td>
		  </tr>	
		  <tr>
		  	<th>修改者</th>
		  	<td>${productSupplierApprove.modifyUser}</td>
		  </tr>	
		  <tr>
		  	<th>修改日期</th>
		  	<td><fmt:formatDate value="${productSupplierApprove.modifyDate}" pattern="yyyy-MM-dd HH:mm:ss" /></td>
		  </tr>	  	  
	  </c-rt:if>
	  <tr>
	  	<td colspan="2">
	  		<input type="hidden" name="approveStatus" id="approveStatus"/>
	  		<input type="hidden" id="spId" value=""/>
				<input type="hidden" id="spName" value=""/>
	  		<c-rt:choose>
	  		<c-rt:when test="${approve eq 'Y'}">
					<yaodian100:checkPermission permissions="ROLE_PM_MANAGER">
			  		<input type="button" id="approveCancelBtn" name="approveCancelBtn" value="不同意申请"/>
			  		<input type="button" id="approveOKBtn" name="approveOKBtn" value="同意申请"/>
		  		</yaodian100:checkPermission>	  			  		
	  		</c-rt:when>
	  		<c-rt:otherwise>
		  		<input type="button" id="cancelBtn" name="cancelBtn" value="取消申请"/>
		  		<input type="button" id="submitBtn" name="submitBtn" value="储存"/>
		  		<input type="button" id="notSaveBtn" name="notSaveBtn" value="放弃修改"/> 			
	  		</c-rt:otherwise>
	  		</c-rt:choose>
	  	</td>
	  </tr>  
	</table>
</s:form>  
<br/><br/>
<table class="tb-1" width="100%">
	<thead>
		<tr>
			<th>日期起</th>
			<th>日期迄</th>
			<th>小标</th>
			<th>售价</th>
		</tr>
	</thead>
	<tbody>
		<c-rt:forEach items="${shelfList}" var="shelf" >
			<tr>
				<td><fmt-rt:formatDate value="${shelf.startDate}" pattern="yyyy-MM-dd HH:mm"/></td>
				<td><fmt-rt:formatDate value="${shelf.endDate}" pattern="yyyy-MM-dd HH:mm"/></td>
				<td>${shelf.promoteName}</td>
				<td><fmt-rt:formatNumber value="${shelf.shelfPrice}" pattern="######.0#"/></td>
			</tr>
		</c-rt:forEach>
	</tbody>
</table>